package graph.day13;

import java.util.Arrays;

public class BubbleSort {

    public static void bubble(int[] arr) {
        int j = arr.length - 1;
        do {
            int x = 0;
            for (int i = 0; i < j; i++) {
                if (arr[i] > arr[i + 1]) {
                    int temp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = temp;
                    x = i;
                }
            }
            j = x;
        } while (j != 0);
    }


    public static void main(String[] args) {
        int[] arr = {5, 4, 3, 2, 1};
        System.out.println(Arrays.toString(arr));
        bubble(arr);
        System.out.println(Arrays.toString(arr));
    }
}
